<template>
	<view class="content">
		<view class="section-0">
			<view class="section-body">
				<view class="section-title">
					{{name}}
				</view>
				<view class="table">
					<view class="header">
						<view class="item"><text>工作名称</text></view>
						<view class="item"><text>完成时间</text></view>
						<view class="item"><text>完成标记</text></view>
						<view class="item"><text>完成状态</text></view>
					</view>
					<view class="body">
						<view class="stage" v-for="stage in list" :key="stage.id">
							<view class="stage-name">
								{{stage.name}}
								<view :class="`action ${expandList.indexOf(stage.id) === -1 ? 'action__active' : ''}`" @click="expandChange(stage.id)">
									<text class="iconfont icon-xiangyou1"></text>
								</view>
							</view>
							<view class="part-container" v-if="expandList.indexOf(stage.id) === -1">
								<view class="part" v-for="part in stage.children" :key="part.id">
									<view class="part-name">
										{{part.name}}
										<view @click="expandChange(part.id)" :class="`action ${expandList.indexOf(part.id) === -1 ? 'action__active' : ''}`">
											<text class="iconfont icon-xiangyou1" style="font-size: 26rpx;"></text>
										</view>
										<view class="statistics">{{part.children.filter(o => o.state !== '未完成').length}} / {{part.children.length}}</view>
									</view>
									<view class="part-container"  v-if="expandList.indexOf(part.id) === -1">
										<table cellspacing="0" cellpadding="0">
											<tr class="cell" v-for="cell in part.children">
												<td class="item">{{cell.name}}</td>
												<td class="item"><text>{{cell.finsh_time ? cell.finsh_time.substring(0, 10) : ''}}</text></td>
												<td class="item">
													<view :class="`state ${renderColor(cell.state)}`"></view>
												</td>
												<td class="item"><text>{{cell.state}}</text></td>
											</tr>
										</table>
									</view>
								</view>
							</view>
							
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { projectManageListApi, projectManageAddApi } from "@/api/project_manage.js";
	export default{
		data() {
			return {
				list: [],
				id: '',
				name: '',
				expandList: []
			}
		},
		methods: {
			renderColor(state) {
				let str = '';
				if (state === '未完成') {str = '';}
				if (state === '已完成') {str = 'green';}
				if (state === '超期完成') {str = 'yellow';}
				if (state === '延时未完成') {str = 'orange';}
				if (state === '超时未完成') {str = 'red';}
				return str;
			},
			async fetchList() {
				uni.showLoading({title: '加载中...'});
				const { data } = await projectManageListApi({project_id: this.id});
				if (data.code === 1) {
					this.list = data.data.children;
				}
				uni.hideLoading();
			},
			expandChange(id) {
				const idx = this.expandList.indexOf(id);
				if (idx !== -1) {
					this.expandList.splice(idx, 1);
				} else {
					this.expandList.push(id);
				}
			},
		},
		onShow() {
			this.fetchList();
		},
		onLoad(data) {
			this.id = data.id
			this.name = data.name
		}
	}
</script>

<style lang="scss" scoped>
	.section-0{
		width: 100%;
		background: #2e5efe;
		.section-body{
			width: 100%;
			height: 100%;
			border-top-left-radius: 50rpx;
			border-top-right-radius: 50rpx;
			background-color: #fff;
			overflow: hidden;
			.table{
				width: 100%;
				.header{
					width: 100%;
					display: flex;
					justify-content: space-between;
					background-color: #dfeeff;
					.item{
						padding: 0 8rpx;
						height: 70rpx;
						line-height: 35rpx;
						width: 25%;
						font-size: 24rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: #3b3c40;
						display: flex;
						align-items: center;
						align-content: space-around;
						justify-content:center;
						text-align: center;
					}
				}
				.body{
					width: 100%;
					.stage{
						width: 100%;
						.action{
							width: 50rpx;
							height: 60rpx;
							line-height: 60rpx;
							float: right;
							text-align: center;
							margin-right: 30rpx;
							transition: 0.3s ease;
							.iconfont{
								display: inline-block;
								font-size: 30rpx;
								transform: rotate(90deg);
							}
						}
						.action__active{
							transform: rotate(-180deg);
						}
						.statistics{
							height: 60rpx;
							line-height: 60rpx;
							float: right;
							margin-right: 30rpx;
							font-size: 22rpx;
						}
						.stage-name{
							box-sizing: border-box;
							width: 100%;
							height: 80rpx;
							line-height: 60rpx;
							background-color: #f0f0ee;
							padding-left: 40rpx;
							font-size: 24rpx;
							font-weight: normal;
							font-stretch: normal;
							letter-spacing: 0rpx;
							color: #3b3c40;
							padding-top: 10rpx;
							padding-bottom: 10rpx;
							@include clear();
						}
						.part-container{
							width: 100%;
							@include clear();
						}
						.part{
							width: 100%;
							.part-name{
								box-sizing: border-box;
								width: 100%;
								height: 60rpx;
								line-height: 60rpx;
								background-color: #f7f7f7;
								padding-left: 40rpx;
								font-size: 22rpx;
								font-weight: normal;
								font-stretch: normal;
								letter-spacing: 0rpx;
								color: #3b3c40;
							}
						
							.cell{
								width: 100%;
								font-size: 20rpx;
								font-weight: normal;
								font-stretch: normal;
								letter-spacing: 0rpx;
								color: #3b3c40;
								background-color: #fff;
								@include clear;
								&:last-child{
									.item{
										border-bottom: none;
									}
								}
								.item{
									box-sizing: border-box;
									padding: 20rpx 10rpx;
									line-height: 35rpx;
									width: 25vw;
									font-size: 20rpx;
									font-weight: normal;
									font-stretch: normal;
									letter-spacing: 0rpx;
									color: #3b3c40;
									vertical-align: middle;
									text-align: center;
									border-right: 1rpx solid #e3e3e1;
									border-bottom: 1rpx solid #e3e3e1;
									word-break: break-all;
									.state{
										display: inline-block;
										width: 25rpx;
										height: 25rpx;
										background-color: #d8d8d5;
										border-radius: 50%;
									}
									
									.green{
										background-color: green;
									}
									.yellow{
										background-color: yellow;
									}
									.orange{
										background-color: orange;
									}
									.red{
										background-color: red;
									}
									// &::before{
									// 	content: '';
									// 	position: absolute;
									// 	right: 0;
									// 	top: 0;
									// 	background-color: #e3e3e1;
									// 	width: 1rpx;
									// 	height: 100%;
									// }
								}
							}
						}
					}
				}
			}
			.section-title{
				width: 100%;
				background-color: #0535d6;
				height: 85rpx;
				line-height: 85rpx;
				text-align: center;
				font-size: 26rpx;
				font-weight: 300;
				font-stretch: normal;
				line-height: 85rpx;
				letter-spacing: 0rpx;
				color: #fafbfd;
				text-overflow: ellipsis;
				overflow: hidden;
				white-space: nowrap;
			}
		}
	}
</style>
